#include "UserView.h"

UserView::UserView(){

    option = 0;
    userName ="";
    password="";
    fullName="";
    user = null;
    users = new LinkedList<User>();

}

User* UserView::createUser()
{
 print = utilities->getInput("Introducing of Users\n");
 userName = utilities->getInput("Enter the User Name: ");
 password = utilities->getInput("Enter The Password");
 fullName = utilities->getInput("Enter The Full Name");
 user = new User(userName,password,fullName);
 return user;

}

void UserView::remove()
{
     showUsers();
     option = utilities->getInt("Choose Which Delete: "); 
     option--;
     users->remove(option);
}
void UserView::edit()
{
     showUsers();
     option = utilities->getInt("Choose Which Modify: ");
     option--;
     user = createUser(); 
     users->edit(user,option);
}

void UserView::add()
{
    user = createUser(); 
    users->add(user);
}


void UserView::showUsers()
{
Node<User>* i = users->getFirst();
int x = 1;

while(i != NULL){
        cout << "User No." << x++ << "\n";
        cout << "User Name: " << i->getData()->getUserName() <<"\n"; 
        cout << "Password: " << i->getData()->getPassword() << "\n";
        cout << "Full Name: " << i->getData()->getFullName() << "\n\n";
        i = i->getNext();        
  }      
 }

void UserView::show(){

 utilities->clearScreen(); 
 utilities->printText( " Maintenances Of Users\n"); 
 utilities->printText("1. Add User\n");
 utilities->printText("2. Modify User\n");
 utilities->printText("3. Delete User\n");
 utilities->printText("4. Exit\n");
 option = utilities->getInt("Choose The Option: ");
 
 switch(option){
 case 1:
 utilities->clearScreen();   
 add(); 
 show(); 
 break;

 case 2: 
  utilities->clearScreen(); 
  edit(); 
  show();
  break;
  
 case 3: 
  utilities->clearScreen();
  remove();
  show(); 
  break;

}
 
}
